public class HomeWork12_07{
    public static void main(String[] args){
        ArrExtraction ae = new ArrExtraction();
        
        int[] a = new int[]{1, 2, 3, 4, 5};
        int[] b = new int[]{3, 4, 5, 6, 7, 8};
        
        int[] c = ae.arrExtraction(a, b);
        for(int item : c){
            System.out.println(item);
        }
    }
}

class ArrExtraction{
    private Filter f;
    public int[] arrExtraction(int[] a, int[] b){
        f = new Filter();
        
        int[] temp = new int[a.length + b.length];
        for(int i = 0; i < temp.length; i++){
            if(i < a.length){
                temp[i] = a[i];
            }else{
                temp[i] = b[i - a.length];
            }
        }
        temp = f.filter(temp);
        return temp;
    }
}

class Filter{
    public int[] filter(int[] arr){
        int tail = arr.length - 1;
        for(int i = 0; i < arr.length; i++){
            for(int j = i + 1; j < tail + 1; ){
                if(arr[i] == arr[j]){
                    int temp = arr[j];
                    arr[j] = arr[tail];
                    arr[tail] = temp;
                    
                    --tail;
                }else{
                    ++j;
                }
            }
        }
        
        int[] newArr = new int[tail + 1];
        for(int i = 0; i < tail + 1; i++){
            newArr[i] = arr[i];
        }
        return newArr;
    }
}